<?php
/// O'My Friends: Personal Social Network Graph on Facebook
/// author : Minkyu Shim (minkyu.shim@gmail.com
class Friend {

    private $fId;
	private $name;

	private $datalist;

	public function __construct($fId, $name){

	    global $data_type_flags;
	    
		$this->fId = $fId;
		$this->name = $name;
		$this->datalist = array();
		
		if(!empty($data_type_flags) && is_array($data_type_flags)){
            foreach ($data_type_flags as $key => $value) {
                if(!isset($this->datalist[$key])){
                    $this->addDatatype($key);
                }
            }
		}
	}
	
	public function getFId(){
		return $this->fId;
	}
	
	public function getName(){
		return $this->name;
	}

	public function getDataList(){
	    return $this->datalist;
	}
	
	public function getNumberOfData($flag){
	    if(isset($this->datalist[$flag])){
	        $subdata = $this->datalist[$flag];
	        if($subdata instanceof Data){
	            return $subdata->getNumberOfData(); 
	        }
	    }
	    return null;
	}
	
	public function increase($flag){
	    if(isset($this->datalist[$flag])){
	        $subdata = $this->datalist[$flag];
	        if($subdata instanceof Data){
	            $subdata->increase(); 
	        }
	    }
	}
	
	public function addDatatype($flag){
	    if(!empty($flag) && !isset($this->datalist[$flag])){
	        $this->datalist[$flag] = new Data($flag);
	    }
	}
	
	public function getNumberOfAllCommunications(){
	    $count = 0;
	    foreach($this->datalist as $key => $value){
	        $count += $value->getNumberOfData();
	    }
        return $count;
	}
	
}

class Data{
    private $flag;
    private $numberOfData;
    
    public function __construct($flag){
        $this->flag = $flag;
        $this->numberOfData = 0;
    }
    
    public function getFlag(){
        return $this->flag;
    }
    
    public function getNumberOfData(){
        return $this->numberOfData;
    }
    
    public function increase(){
        $this->numberOfData++;
    }
}